package com.hanhanxiaochong.zhongxiangchuanmei.view.shop.adapter;

import android.content.Context;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ShopTypeBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.CommonAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.OnItemClickListener;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;

import java.util.List;

/**
 * Author : 贾桐
 * E-mail : 653773284@qq.com
 * Time   : 2018/5/9.
 * Desc   :
 */

public class ShopNextFirstAdapter extends CommonAdapter<ShopTypeBean.TypeBean> {

    private int selectedIndex = 0;
    private OnItemClickListener mOnItemClickListener;

    public ShopNextFirstAdapter(Context context, int layoutId, List<ShopTypeBean.TypeBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ShopTypeBean.TypeBean bean, int position) {
        TextView firstType = holder.getView(R.id.tv_first_type);
        firstType.setText(bean.getName());
        if (position == selectedIndex) {
            firstType.setSelected(true);
        } else {
            firstType.setSelected(false);
        }
        holder.itemView.setOnClickListener(v -> {
            selectedIndex = position;
            firstType.setSelected(true);
            notifyDataSetChanged();
            mOnItemClickListener.onItemClick(this,position);
        });
    }

    public void setmOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

}
